package org.wu.framework.inner.lazy.orm.spring.event;

import org.springframework.beans.factory.InitializingBean;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.event.LazyOrmEvent;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.event.LazyOrmEventConsumer;
import org.wu.framework.lazy.orm.database.sql.expand.database.persistence.method.LazyOperationParameter;

import java.util.List;

public class EventScanner implements InitializingBean {

    private final LazyOperationParameter lazyOperationParameter;

    private final List<LazyOrmEvent<?>> lazyOrmEvents;
    private final LazyLambdaStream lazyLambdaStream;

    public EventScanner(LazyOperationParameter lazyOperationParameter, List<LazyOrmEvent<?>> lazyOrmEvents, LazyLambdaStream lazyLambdaStream) {
        this.lazyOperationParameter = lazyOperationParameter;
        this.lazyOrmEvents = lazyOrmEvents;
        this.lazyLambdaStream = lazyLambdaStream;
    }


    /**
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {

        try {
            LazyOrmEventConsumer lazyOrmEventConsumer = new LazyOrmEventConsumer(
                    lazyOperationParameter,
                    lazyOrmEvents,
                    lazyLambdaStream
            );
            lazyOrmEventConsumer.run();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
